
const Leave = require('../model/leave.model')
const { queryUtil } = require('../utils/query.util')
class LeaveService {
    async createLeave(leave) {
        const res = await Leave.create(leave)
        return res ? res.dataValues : null
    }

    async queryAll(whereOpt) {
        const res = await Leave.findAll({ where: whereOpt })

        console.log(res.dataValues);
        return res
    }

    async adminQueryAll(pageNum, pageSize, whereOpt) {
        const res = await queryUtil(pageNum, pageSize, whereOpt, Leave)
        return res
    }

    async updateById(leave) {
        const whereOpt = { id: leave.id }
        const { id, ...newLeave } = leave
        const res = await Leave.update(newLeave, { where: whereOpt })

        return res[0] > 0 ? true : false
    }

    async removeById(id) {
        const res = await Leave.destroy({ where: { id } })
        console.log(res);
    }
}

module.exports = new LeaveService()